/*package com.gogowan.agroenterprise;

//import java.util.ArrayList;
import java.util.HashSet;
//import java.util.List;
import java.util.Set;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

//import com.gogowan.agriculture.model.MaterialBatch;
import com.gogowan.agroenterprise.R;
import com.gogowan.agroenterprise.barcode.Intents;
import com.gogowan.agroenterprise.base.BaseActivity;
import com.gogowan.agroenterprise.contorl.MyAsyncTask;
import com.gogowan.agroenterprise.model.CodeActivationInfo;
import com.gogowan.agroenterprise.model.LoginResultInfo;
import com.gogowan.agroenterprise.model.MaterialBatchResultInfo;
import com.gogowan.agroenterprise.model.Message;
import com.gogowan.agroenterprise.model.ResultInfo;
import com.gogowan.agroenterprise.model.SalesPlaceDict;
import com.gogowan.agroenterprise.model.SellMaterialInfo;
import com.gogowan.agroenterprise.utils.Utils;

*//**
 * @author Maniac
 * @功能描述 记录销售信息 并上传
 * 					步骤：先拍首尾码 得到批次列表以及每个批次所对应的产品名称，
 * 								用户只需填写销售信息。
 *//*
public class SalesActivityNew extends BaseActivity{
	
	private static int START = 1;	//调用拍码requestCode
	private static int END = 2;

	private Button takeStart;        //起始  拍码按钮
	private Button takeEnd;           //截止  拍码按钮
	private EditText startText;    //起始  I-OID显示
	private EditText endText;		//截止  I-OID显示
	private EditText salesEnterprises;//销售单位
	private EditText salesPerson;//销售人员
	//private EditText dealer;//经销商
	//private EditText purchasePerson;//采购人员
	private Button save;
	private Button back;
	
	private EditText batch;				//选择批次
	private Spinner channel;           //销售渠道
	private EditText productName;//销售产品名称
	
	private ProgressDialog progressDialog;
	private SharedPreferences preferences;
	private MaterialBatchResultInfo resultInfo;
	//private MaterialBatch[] batchs;
	private SalesPlaceDict[] salesPlaceDict;
	//private String selectedProductName;
	private long selectedChannel;
	private long selectedBatch;
	private long selectedMaterialId;
	private long enterpriseId;
	private long personId;
	private String personName;
	private String enterpriseName;
	private String startCode;
	private String endCode;
	//private String[] newMaterial; //去重后的商品名称数组
	//private MaterialBatch [] newMb; //选中商品后对应的数组
	//private List<MaterialBatch> newArray;
	//private String[] newBatchs;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.sales);
		
		takeStart = (Button)findViewById(R.id.sales_btn_paima_start);
		takeEnd = (Button)findViewById(R.id.sales_btn_paima_end);
		startText = (EditText)findViewById(R.id.sales_start_ed);
		endText = (EditText)findViewById(R.id.sales_end_ed);
		salesEnterprises = (EditText)findViewById(R.id.sales_enterprises);
		salesPerson = (EditText)findViewById(R.id.sales_person);
		
		save =(Button)findViewById(R.id.sales_save_btn);
		back =(Button)findViewById(R.id.sales_backBtn);
		
		batch = (EditText)findViewById(R.id.sales_batch);
		channel = (Spinner)findViewById(R.id.sales_channel);
		productName = (EditText)findViewById(R.id.sales_product_name);
		
		preferences = getSharedPreferences("LoginINfo", MODE_PRIVATE);
		enterpriseId = preferences.getLong("enterpriseid", 0);
		personId = preferences.getLong("personid", 0);
		
		
		if (string == null || string.equals("")) {
			
			new AlertDialog.Builder(SalesActivityNew.this).setTitle("提示")
				.setMessage("数据初始化失败").setPositiveButton("确定", new DialogInterface.OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					SalesActivityNew.this.finish();
				}
			}).setCancelable(false).create().show();
			
		} else {
			LoginResultInfo loginResultInfo = (LoginResultInfo)Utils.fromJSON(string, LoginResultInfo.class);
			salesPlaceDict = loginResultInfo.getSalesplacedict();
			personName = MyApplication.mSettings.getString("username","");
			enterpriseName = loginResultInfo.getEnterpriseinfo().getEname();
			
			salesEnterprises.setText(enterpriseName);
			salesPerson.setText(personName);
			
			if (salesPlaceDict == null || salesPlaceDict.length == 0) {
				showFinishDialog("初始化销售经销商失败！");
			} else {
				String [] m1 = new String[salesPlaceDict.length];
				for (int i = 0; i < salesPlaceDict.length; i++) {
					m1[i] = salesPlaceDict[i].getSalesplacename();
				}
				ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(SalesActivityNew.this,android.R.layout.simple_spinner_item,m1);
				//设置下拉列表的风格
				 adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
				 //将adapter 添加到spinner中
				 channel.setAdapter(adapter1);
			}
			
		}
		
		setFalse();
		takeStart.setOnClickListener(startPaima);
		takeEnd.setOnClickListener(endPaima);
		save.setOnClickListener(saveCallback);
		back.setOnClickListener(backToIndex);
		batch.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				for (int i = 0; i < newMb.length; i++) {
					if (newBatchs[position].equals(newArray.get(i).getBatchcode())) {
						selectedBatch = newArray.get(i).getBatchid();
					}
				}
			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {
				// donothing
			}
		});
		
		
		productName.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				try {
					
				// 选中产品在组建出涉及这个产品的所有批次列表
				newArray = new ArrayList<MaterialBatch>();
				for (int i = 0; i < batchs.length; i++) {
					if (batchs[i].getMaterialfullname().equals(newMaterial[position])) {
						newArray.add(batchs[i]);
						selectedMaterialId = batchs[i].getMaterialid();
					}
				}
				
				newMb = (MaterialBatch[]) newArray.toArray(new MaterialBatch[newArray.size()]);
				
				newBatchs = new String[newMb.length];
				for (int i = 0; i < newMb.length; i++) {
					newBatchs[i] = newMb[i].getBatchcode();
				}
				ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(SalesActivity.this,android.R.layout.simple_spinner_item,newBatchs);
				//设置下拉列表的风格
				 adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
				 //将adapter 添加到spinner中
				 batch.setAdapter(adapter2);
				 
				batch.setEnabled(true);
				batch.setFocusable(true);
				
				} catch (Exception e) {
					setFalse();
					new AlertDialog.Builder(SalesActivity.this).setTitle("提示")
					.setMessage("数据初始化失败").setPositiveButton("确定", new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						
					}
				}).setCancelable(false).create().show();
				}
			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {
				
			}
		});
		
		channel.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				channel.setSelection(position);
				selectedChannel = salesPlaceDict[position].getSalesplaceid();
			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {
				//do nothing
			}
		});
	}

	
	  private void showFinishDialog(String string){
	    	new AlertDialog.Builder(SalesActivityNew.this).setTitle("警告")
			.setMessage(string).setCancelable(false).setPositiveButton("确定", new DialogInterface.OnClickListener() {
		
				@Override
				public void onClick(DialogInterface dialog, int which) {
					SalesActivityNew.this.finish();
				}
			}).create().show();
	    }
	  
	public void setTrue(){
		
		channel.setEnabled(true);
		channel.setFocusable(true);
		save.setEnabled(true);
		save.setFocusable(true);
	}
	
	private void setFalse(){
		
		takeEnd.setEnabled(false);
		takeEnd.setFocusable(false);
//		channel.setEnabled(false);
//		channel.setFocusable(false);
		save.setEnabled(false);
		save.setFocusable(false);
	}
	
	
	 *  拍起始码按钮事件
	 
	public Button.OnClickListener startPaima = new Button.OnClickListener(){

		@Override
		public void onClick(View v) {
			AlertDialog.Builder builder = new AlertDialog.Builder(
					SalesActivityNew.this);
			builder.setTitle("选择方式");
			builder.setItems(new String[] { "拍产品码", "输产品码" },new AlertDialog.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog,int which) {
					if (which == 0) {
						Intent intent = new Intent(Intents.Scan.ACTION);
						startActivityForResult(intent, START);
					} 
					else if (which == 1) {
						LayoutInflater inflater = LayoutInflater.from(SalesActivityNew.this);
						View view = inflater.inflate(R.layout.dialog_edit,null);
						final EditText text = (EditText) view.findViewById(R.id.dialog_edittext);
						AlertDialog.Builder builder1 = new AlertDialog.Builder(SalesActivityNew.this);
						builder1.setTitle("请输入您要拍的码号");
						builder1.setView(view);
						builder1.setPositiveButton("确定", new DialogInterface.OnClickListener() {
							
							@Override
							public void onClick(DialogInterface dialog, int which) {
								String contents = text.getText().toString().trim();
								if (contents == null || contents.equals("")) {
									Toast.makeText(SalesActivityNew.this, "码内容为空或不符合I-OID规则", Toast.LENGTH_LONG).show();
								} else {
									if (Utils.isNumeric(contents)) {
										
										startText.setText(contents);
										takeEnd.setEnabled(true);
										takeEnd.setFocusable(true);
										
										CodeActivationInfo requestBatchsInfo = new CodeActivationInfo();
										requestBatchsInfo.setStartcode(contents);
										requestBatchsInfo.setEnterpriseid(enterpriseId);
										
										FirstGetAsyn firstGetAsyn = new FirstGetAsyn();
										firstGetAsyn.execute(requestBatchsInfo);
										
									} else {
										Toast.makeText(SalesActivityNew.this, getString(R.string.code_error), Toast.LENGTH_LONG).show();
									}
								}
							}
						});
						builder1.setNegativeButton("取消", new DialogInterface.OnClickListener() {
							
							@Override
							public void onClick(DialogInterface dialog, int which) {
								
							}
						});
						builder1.create().show();
					}
				}
			}); 
			builder.create().show();
		
		}
	};
	
	 *  拍截止码按钮事件
	 
	public Button.OnClickListener endPaima = new Button.OnClickListener(){

		@Override
		public void onClick(View v) {
			AlertDialog.Builder builder = new AlertDialog.Builder(
					SalesActivityNew.this);
			builder.setTitle("选择方式");
			builder.setItems(new String[] { "拍产品码", "输产品码" },new AlertDialog.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog,int which) {
					if (which == 0) {
						Intent intent = new Intent(Intents.Scan.ACTION);
						startActivityForResult(intent, END);
					} 
					else if (which == 1) {
						LayoutInflater inflater = LayoutInflater.from(SalesActivityNew.this);
						View view = inflater.inflate(R.layout.dialog_edit,null);
						final EditText text = (EditText) view.findViewById(R.id.dialog_edittext);
						AlertDialog.Builder builder1 = new AlertDialog.Builder(SalesActivityNew.this);
						builder1.setTitle("请输入您要拍的码号");
						builder1.setView(view);
						builder1.setPositiveButton("确定", new DialogInterface.OnClickListener() {
							
							@Override
							public void onClick(DialogInterface dialog, int which) {
								String contents = text.getText().toString().trim();
								if (contents == null || contents.equals("")) {
									Toast.makeText(SalesActivityNew.this, "码内容不能为空或不符合I-OID规则", Toast.LENGTH_LONG).show();
								} else {
									if (Utils.isNumeric(contents)) {
										
										endText.setText(contents);
										progressDialog = ProgressDialog.show(SalesActivityNew.this, "提示", "正在查询....", true, false);
										
										CodeActivationInfo requestBatchsInfo = new CodeActivationInfo();
										requestBatchsInfo.setStartcode(startCode);
										requestBatchsInfo.setEndcode(contents);
										requestBatchsInfo.setEnterpriseid(enterpriseId);
										
										
										RequestBatchsAsyn requestBatchsAsyn = new RequestBatchsAsyn();
										requestBatchsAsyn.execute(requestBatchsInfo);
									
									} else {
										Toast.makeText(SalesActivityNew.this, getString(R.string.code_error), Toast.LENGTH_LONG).show();
									}
								}
							}
						});
						builder1.setNegativeButton("取消", new DialogInterface.OnClickListener() {
							
							@Override
							public void onClick(DialogInterface dialog, int which) {
								
							}
						});
						builder1.create().show();
					}
				}
			}); 
			builder.create().show();
		}
	};
	
	*//**
	 * 保存按钮事件
	 *//*
	public Button.OnClickListener saveCallback = new Button.OnClickListener(){

		@Override
		public void onClick(View v) {
			save.setEnabled(false);
			save.setFocusable(false);
			try {
				SellMaterialInfo sellMaterialInfo = new SellMaterialInfo();
				
				if (startCode!=null&&Utils.isNumeric(startCode)&&!(startCode.equals(""))) {
					sellMaterialInfo.setStartcode(startCode);
				} else {
					setFalse();
					startText.setText("");
					endText.setText("");
					startCode = null;
					endCode = null;
					Toast.makeText(SalesActivityNew.this, "起始码内容为空或不符合I-OID规则", Toast.LENGTH_LONG).show();
					return;
				}
				
				if (endCode!=null&&!(endCode.equals(""))) {
					sellMaterialInfo.setEndcode(endCode);
				} else {
					setFalse();
					startText.setText("");
					endText.setText("");
					startCode = null;
					endCode = null;
					Toast.makeText(SalesActivityNew.this, "截止码内容为空或不符合I-OID规则", Toast.LENGTH_LONG).show();
					return;
				}
				
				sellMaterialInfo.setBatchid(selectedBatch);
				sellMaterialInfo.setMaterialid(selectedMaterialId);
				sellMaterialInfo.setEnterpriseid(enterpriseId);
				sellMaterialInfo.setPersonid(personId);
				sellMaterialInfo.setSalesplaceid(selectedChannel);
				
				progressDialog = ProgressDialog.show(SalesActivityNew.this, "提示", "正在保存....", true, false);
				SaveAsyn saveAsyn = new SaveAsyn();
				saveAsyn.execute(sellMaterialInfo);
			} catch (Exception e) {
				new AlertDialog.Builder(SalesActivityNew.this).setTitle("警告")
				.setMessage("数据保存有误！").setCancelable(false).setPositiveButton("确定", new DialogInterface.OnClickListener() {
			
					@Override
					public void onClick(DialogInterface dialog, int which) {
						startText.setText("");
						endText.setText("");
						startCode = null;
						endCode = null;
						setFalse();
					}
				}).create().show();
			}
		}
		
	};
	
	 *  返回主页按钮事件
	 
	public Button.OnClickListener backToIndex = new Button.OnClickListener(){

		@Override
		public void onClick(View v) {
			AlertDialog alert = new AlertDialog.Builder(SalesActivityNew.this)
			.setTitle(getString(R.string.tip_back)).setCancelable(false)
			.setMessage(getString(R.string.tip_back_description))
					.setNegativeButton("否", new AlertDialog.OnClickListener() {
						public void onClick(DialogInterface dialog,
								int whichButton) {
							// do nothing
						}
					})
					.setPositiveButton("是", new AlertDialog.OnClickListener() {
						public void onClick(DialogInterface dialog,
								int whichButton) {
							// 结束应用程序
							SalesActivityNew.this.finish();
						}
					}).create();
			alert.show();
		}
	};
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
			AlertDialog alert = new AlertDialog.Builder(SalesActivityNew.this)
			.setTitle(getString(R.string.tip_back)).setCancelable(false)
			.setMessage(getString(R.string.tip_back_description))
					.setNegativeButton("否", new AlertDialog.OnClickListener() {
						public void onClick(DialogInterface dialog,
								int whichButton) {
							// do nothing
						}
					})
					.setPositiveButton("是", new AlertDialog.OnClickListener() {
						public void onClick(DialogInterface dialog,
								int whichButton) {
							// 结束应用程序
							SalesActivityNew.this.finish();
						}
					}).create();
			alert.show();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}
	*//**
	 * 拍码返回处理
	 *//*
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {

		if (resultCode == RESULT_OK) {
			
			if (requestCode == START) {
				
				String contents = data.getStringExtra("SCAN_RESULT").trim();
				String [] ss = contents.split("=");
				String content = ss[ss.length-1];
				
				
				startText.setText(content);
				takeEnd.setEnabled(true);
				takeEnd.setFocusable(true);
					
				CodeActivationInfo requestBatchsInfo = new CodeActivationInfo();
				requestBatchsInfo.setStartcode(content);
				requestBatchsInfo.setEnterpriseid(enterpriseId);
					
				FirstGetAsyn firstGetAsyn = new FirstGetAsyn();
				firstGetAsyn.execute(requestBatchsInfo);
				
			} else if (requestCode == END) {
				
				String contents = data.getStringExtra("SCAN_RESULT").trim();
				String [] ss = contents.split("=");
				String content = ss[ss.length-1];
				
				endText.setText(content);
					
				progressDialog = ProgressDialog.show(SalesActivityNew.this, "提示", "正在查询....", true, false);
					
				CodeActivationInfo requestBatchsInfo = new CodeActivationInfo();
				requestBatchsInfo.setStartcode(startCode);
				requestBatchsInfo.setEndcode(content);
				requestBatchsInfo.setEnterpriseid(enterpriseId);
					
					
				RequestBatchsAsyn requestBatchsAsyn = new RequestBatchsAsyn();
				requestBatchsAsyn.execute(requestBatchsInfo);
			}
		}
		super.onActivityResult(requestCode, resultCode, data);
	}
	
	
	*//**
	 * @author Maniac
	 * @描述 根据首尾I-OID码请求批次列表]
	 * (改) 判断首尾码是不是在同一个批次
	 *//*
	private class RequestBatchsAsyn extends MyAsyncTask{

		@Override
		protected void onPostExecute(Object res) {
			if (res == null || res.equals("")) {
				Toast.makeText(SalesActivityNew.this, getString(R.string.server_error), Toast.LENGTH_LONG).show();
			} else {
				
				Message message = (Message) Utils.fromJSON((String) res, Message.class);
				String string = Utils.getMessageContent(message);
				if (string == null || string.equals("")) {
					endText.setText("");
					endCode = null;
					Toast.makeText(SalesActivityNew.this, getString(R.string.analyse_error), Toast.LENGTH_LONG).show();
				} else {
					ResultInfo resultInfo = (ResultInfo)Utils.fromJSON(string, ResultInfo.class);
					//int i = resultInfo.getResult();
					if (resultInfo.getResult() == 4010) {
						endCode = endText.getText().toString().trim();
//						save.setFocusable(true);
//						save.setEnabled(true);
						setTrue();
						Toast.makeText(SalesActivityNew.this, resultInfo.getResultinfo(), Toast.LENGTH_LONG).show();
						try {
							batchs = resultInfo.getMbatcharray();						//
							if (batchs == null || batchs.length == 0) {
								endText.setText("");
								Toast.makeText(SalesActivity.this, "批次列表空", Toast.LENGTH_LONG).show();
							}else {
								
								endCode = endText.getText().toString().trim();
								
								int length = batchs.length;											//将返回的数据中的商品名称拿出来
								String [] materials = new String[length];					//组成一个新数组
								for (int i = 0; i < length; i++) {										//
									materials[i] = batchs[i].getMaterialfullname();		//
								}
								newMaterial = toDiffArray(materials);      				//数组去重
								
								ArrayAdapter<String> adapter = new ArrayAdapter<String>(SalesActivity.this,android.R.layout.simple_spinner_item,newMaterial);
								//设置下拉列表的风格
								 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
								 //将adapter 添加到spinner中
								 productName.setAdapter(adapter);
								 setTrue();
							}
						} catch (Exception e) {
							Toast.makeText(SalesActivity.this, "批次列表空", Toast.LENGTH_LONG).show();
							endText.setText("");
						}
						
					} else {
						Toast.makeText(SalesActivityNew.this, resultInfo.getResultinfo(), Toast.LENGTH_LONG).show();
						endText.setText("");
						//不清空起始码
//						startText.setText("");
//						productName.setText("");
//						batch.setText("");
//						startCode = null;
						endCode = null;
						//setFalse();
					}
				}
			}
			
			progressDialog.dismiss();
			super.onPostExecute(res);
		}

		@Override
		protected Object doInBackground(Object... params) {
			CodeActivationInfo request = (CodeActivationInfo)params[0];
			String json = Utils.toJSON(request);
			Message message = new Message(4000, true, json);
			String res = Utils.postCommit(getString(R.string.first_url)
					+ getString(R.string.first_url_page), message);
			return res;
		}
	}
	
	*//**
	 * @author Administrator
	 * @功能 保存信息
	 *//*
	private class SaveAsyn extends MyAsyncTask{

		@Override
		protected void onPostExecute(Object res) {
			if (res == null || res.equals("")) {
				
				Toast.makeText(SalesActivityNew.this, getString(R.string.server_error), Toast.LENGTH_LONG).show();
			} else {
				
				Message message = (Message) Utils.fromJSON((String) res, Message.class);
				String string = Utils.getMessageContent(message);
				if (string == null || string.equals("")) {
					startText.setText("");
					endText.setText("");
					startCode = null;
					endCode = null;
					setFalse();
					productName.setText("");
					batch.setText("");
					Toast.makeText(SalesActivityNew.this, getString(R.string.analyse_error), Toast.LENGTH_LONG).show();
				} else {
					ResultInfo resultInfo = (ResultInfo)Utils.fromJSON(string, ResultInfo.class);
					if (resultInfo.getResult() == 4110) {
						Toast.makeText(SalesActivityNew.this, resultInfo.getResultinfo(), Toast.LENGTH_LONG).show();
						SalesActivityNew.this.finish();
					} else {
						startText.setText("");
						endText.setText("");
						productName.setText("");
						batch.setText("");
						startCode = null;
						endCode = null;
						setFalse();
						Toast.makeText(SalesActivityNew.this, resultInfo.getResultinfo(), Toast.LENGTH_LONG).show();
					}
				}
			}
			progressDialog.dismiss();
			super.onPostExecute(res);
		}

		@Override
		protected Object doInBackground(Object... params) {
			SellMaterialInfo sellMaterialInfo = (SellMaterialInfo) params[0];
			String json = Utils.toJSON(sellMaterialInfo);
			Message message = new Message(4100, true, json);
			String res = Utils.postCommit(getString(R.string.first_url)
					+ getString(R.string.first_url_page), message);
			return res;
		}
		
	}
	
	*//**
	 * 根据起始码请求当前码所在的产品批次号和产品名称
	 *//*
	private class FirstGetAsyn extends MyAsyncTask{

		@Override
		protected void onPostExecute(Object res) {
			if (res == null || res.equals("")) {
				startText.setText("");
				startCode = null;
				setFalse();
				Toast.makeText(SalesActivityNew.this, getString(R.string.server_error), Toast.LENGTH_LONG).show();
			} else {
				
				Message message = (Message) Utils.fromJSON((String) res, Message.class);
				String string = Utils.getMessageContent(message);
				if (string == null || string.equals("")) {
					startText.setText("");
					endText.setText("");
					productName.setText("");
					batch.setText("");
					startCode = null;
					setFalse();
					Toast.makeText(SalesActivityNew.this, getString(R.string.analyse_error), Toast.LENGTH_LONG).show();
				} else {
					resultInfo = (MaterialBatchResultInfo)Utils.fromJSON(string, MaterialBatchResultInfo.class);
					
					if (resultInfo.getResult() == 4210) {
						
						startCode = startText.getText().toString().trim();
						
						String productNameString = resultInfo.getMbatcharray()[0].getMaterialfullname();
						if (productNameString != null && !productNameString.equals("")) {
							productName.setText(productNameString);
						} else {
							startCode = null;
							startText.setText("");
							endText.setText("");
							productName.setText("");
							batch.setText("");
							return;
						}
						
						String batchNameString = resultInfo.getMbatcharray()[0].getBatchcode();
						if (batchNameString != null && !batchNameString.equals("")) {
							batch.setText(batchNameString);
						} else {
							startCode = null;
							startText.setText("");
							endText.setText("");
							productName.setText("");
							batch.setText("");
							return;
						}
						
						takeEnd.setFocusable(true);
						takeEnd.setEnabled(true);
					} else {
						takeEnd.setFocusable(false);
						takeEnd.setEnabled(false);
						startCode = null;
						startText.setText("");
						endText.setText("");
						productName.setText("");
						batch.setText("");
						Toast.makeText(SalesActivityNew.this, resultInfo.getResultinfo(), Toast.LENGTH_LONG).show();
					}
				}
			}
			super.onPostExecute(res);
		}

		@Override
		protected Object doInBackground(Object... params) {
			CodeActivationInfo request = (CodeActivationInfo)params[0];
			String json = Utils.toJSON(request);
			Message message = new Message(4200, true, json);
			String res = Utils.postCommit(getString(R.string.first_url)
					+ getString(R.string.first_url_page), message);
			return res;
		}
		
	}
	
	*//**
	 * 数组去重
	 * @param strings
	 * @return
	 *//*
	public static String [] toDiffArray(String [] s){
        Set<String> set = new HashSet<String>();
        for(String sa :s){
                set.add(sa);
        }
        return set.toArray(new String[]{});
	}
}
*/